package cn.starrysky108.simpleerp.user.service;

import cn.starrysky108.simpleerp.core.util.entity.IpInfo;
import cn.starrysky108.simpleerp.core.util.HttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;

import java.util.concurrent.Future;

/**
 * @author Carl Lee
 */
@Slf4j
@Service
public class OnlineDeviceInfoServiceImpl implements OnlineDeviceInfoService {
    /**
     * 查询ip信息
     *
     * @param ip ip地址
     * @return ip information
     */
    @Override
    @Async
    public Future<IpInfo> getIpInfo(String ip) {
        IpInfo info = null;
        try {
            info = HttpUtil.getIpInfo(ip);
        } catch (RestClientException e) {
            log.error(e.getMessage());
        }
        return new AsyncResult<>(info);
    }
}
